﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace TaskProgramming
{
    class _006_Child
    {
        public static void Test()
        {
            var parent = new Task(() =>
            {
                Console.WriteLine("Parent");

                new Task(() =>
                {
                    Thread.Sleep(100);
                    Console.WriteLine("Child #1");
                }, TaskCreationOptions.AttachedToParent).Start();

                new Task(() =>
                {
                    Thread.Sleep(150);
                    Console.WriteLine("Child #2");
                }, TaskCreationOptions.AttachedToParent).Start();
            });

            parent.ContinueWith((x) =>
            {
                Console.WriteLine("Child #3");
            });

            parent.Start();
            Console.ReadLine();
        }
    }
}
